@import "../shared-imports/vars.less";
@import "imports/icons.less";

// idle
.jw-state-idle {

    /* hide control bar and clear display container padding on idle state unless cast available flag is set */
    &:not(.jw-flag-cast-available) {
        .jw-display {
            padding: 0;
        }
    }

    .jw-controls {
        background: @controlbar-background;
    }

    &.jw-flag-cast-available:not(.jw-flag-audio-player),
    &.jw-flag-cardboard-available {
        .jw-controlbar {
            .jw-slider-time,
            .jw-icon:not(.jw-icon-cardboard):not(.jw-icon-cast):not(.jw-icon-airplay) {
                display: none;
            }
        }
    }
}

// buffering
.jwplayer.jw-state-buffering {
    .jw-display-icon-display .jw-icon {
        animation: spin 2s linear infinite;

        .jw-svg-icon-buffer {
            display: block;
        }

        @keyframes spin {
            100% {
                transform: rotate(360deg);
            }
        }
    }

    .jw-icon-playback {
        .jw-svg-icon-play {
            display: none;
        }
    }

    .jw-icon-display .jw-svg-icon-pause {
        display: none;
    }
}

// playing
.jwplayer.jw-state-playing {
    .jw-display .jw-icon-display,
    .jw-icon-playback {
        .jw-svg-icon-play {
            display: none;
        }

        .jw-svg-icon-pause {
            display: block;
        }
    }

    &.jw-flag-user-inactive:not(.jw-flag-audio-player):not(.jw-flag-casting):not(.jw-flag-media-audio) {
        .jw-controls-backdrop {
            opacity: 0;
        }

        .jw-logo-bottom-left,
        &:not(.jw-flag-autostart) .jw-logo-bottom-right {
            bottom: 0;
        }
    }
}

.jwplayer .jw-icon-playback {
    .jw-svg-icon-stop {
        display: none;
    }
}

// paused
.jwplayer.jw-state-paused,
.jwplayer.jw-state-idle,
.jwplayer.jw-state-error,
.jwplayer.jw-state-complete {
    .jw-svg-icon-pause {
        display: none;
    }
}

.jwplayer.jw-state-error,
.jwplayer.jw-state-complete,
.jwplayer.jw-state-buffering {
    .jw-icon-display .jw-svg-icon-play {
        display: none;
    }
}

.jwplayer:not(.jw-state-buffering) {
    .jw-svg-icon-buffer {
        display: none;
    }
}

.jwplayer:not(.jw-state-complete) {
    .jw-svg-icon-replay {
        display: none;
    }
}

.jwplayer:not(.jw-state-error) {
    .jw-svg-icon-error {
        display: none;
    }
}

// complete
.jwplayer.jw-state-complete {
    .jw-display {
        .jw-icon-display {
            .jw-svg-icon-replay {
                display: block;
            }
        }

        .jw-text {
            display: none;
        }
    }

    .jw-controls {
        background: @controlbar-background;
        height: 100%;
    }
}

// Show the play icon
.jw-state-idle .jw-icon-display,
.jwplayer.jw-state-paused .jw-icon-playback,
.jwplayer.jw-state-paused .jw-icon-display,
.jwplayer.jw-state-complete .jw-icon-playback {
    .jw-svg-icon-pause {
        display: none;
    }
}

// Only show the play display icon
.jw-state-idle,
.jwplayer.jw-state-buffering,
.jwplayer.jw-state-complete,
body .jw-error,
body .jwplayer.jw-state-error {
    .jw-display-icon-rewind,
    .jw-display-icon-next {
        display: none;
    }
}

body .jw-error,
body .jwplayer.jw-state-error {
    .jw-icon-display {
        cursor: default;

        .jw-svg-icon-error {
            display: block;
        }
    }

    .jw-controls-backdrop {
        &:extend(.jw-state-idle .jw-controls-backdrop);
    }
}

body .jw-error .jw-icon-container {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
}

body .jwplayer.jw-state-error.jw-flag-audio-player {
    .jw-preview {
        display: none;
    }

    .jw-title {
        padding-top: 4px;
    }

    .jw-title-primary {
        width: auto;
        display: inline-block;
        padding-right: 0.5ch;
    }

    .jw-title-secondary {
        width: auto;
        display: inline-block;
        padding-left: 0;
    }
}

// Hide control bar
body .jwplayer.jw-state-error,
.jwplayer.jw-state-idle:not(.jw-flag-audio-player):not(.jw-flag-cast-available):not(.jw-flag-cardboard-available) {
    .jw-controlbar {
        display: none;
    }

    .jw-settings-menu {
        height: 100%;
        top: 0;
        bottom: 0;
    }

    .jw-display {
        padding: 0;
    }

    .jw-logo-bottom-left,
    .jw-logo-bottom-right {
        bottom: 0;
    }
}

/* Indentation sometimes complains about multiple selections when :not()s are included */
/* stylelint-disable indentation */
// Hide display
.jwplayer.jw-state-playing.jw-flag-user-inactive .jw-display {
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
}

.jwplayer.jw-state-playing:not(.jw-flag-touch):not(.jw-flag-small-player):not(.jw-flag-casting),
.jwplayer.jw-state-paused:not(.jw-flag-touch):not(.jw-flag-small-player):not(.jw-flag-casting):not(.jw-flag-play-rejected) {
    .jw-display {
        display: none;
    }
}
/* stylelint-enable indentation */
.jwplayer.jw-state-paused.jw-flag-play-rejected:not(.jw-flag-touch):not(.jw-flag-small-player):not(.jw-flag-casting) {
    .jw-display-icon-rewind,
    .jw-display-icon-next {
        display: none;
    }
}

// Hide text
.jwplayer.jw-state-buffering .jw-display-icon-display,
.jwplayer.jw-state-complete .jw-display {
    .jw-text {
        display: none;
    }
}
